package com.mhealth365.study.adapter;

import java.util.ArrayList;

import com.mhealth365.study.domain.ExaminationPaper;
import com.mhealth365.study.ui.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ExaminationPaperAdapter extends BaseAdapter {
	private LayoutInflater mInflater;
	private ArrayList<ExaminationPaper> mData = new ArrayList<ExaminationPaper>();

	public ExaminationPaperAdapter(Context context) {
		mInflater = LayoutInflater.from(context);
	}

	public ExaminationPaperAdapter(Context context,
			ArrayList<ExaminationPaper> data) {
		mInflater = LayoutInflater.from(context);
		mData = data;
	}

	public void refreshData(ArrayList<ExaminationPaper> group) {
		mData.clear();
		mData.addAll(group);
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		return mData.size();
	}

	public void setData(ArrayList<ExaminationPaper> records) {
		this.mData = records;
	}

	@Override
	public Object getItem(int id) {
		return mData.get(id);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.examination_paper_item,null);
			holder.examination_paper_item_id = (TextView) convertView.findViewById(R.id.examination_paper_item_id);
			holder.examination_paper_item_name = (TextView) convertView.findViewById(R.id.examination_paper_item_name);
			holder.examination_paper_item_subject = (TextView) convertView.findViewById(R.id.examination_paper_item_subject);
			holder.examination_paper_item_subject_teacher = (TextView) convertView.findViewById(R.id.examination_paper_item_subject_teacher);
			holder.examination_paper_item_effect_time = (TextView) convertView.findViewById(R.id.examination_paper_item_effect_time);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		ExaminationPaper examinationPaper = mData.get(position);
		holder.examination_paper_item_id.setText(examinationPaper.getId());
		holder.examination_paper_item_name.setText(examinationPaper.getName());
		holder.examination_paper_item_subject.setText(examinationPaper.getSubject());
		holder.examination_paper_item_subject_teacher.setText(examinationPaper.getSubject_teacher());
		holder.examination_paper_item_effect_time.setText(examinationPaper.getEffect_time());
		return convertView;
	}

	class ViewHolder {
		TextView examination_paper_item_id, examination_paper_item_name,
				examination_paper_item_subject,
				examination_paper_item_subject_teacher,
				examination_paper_item_effect_time;
	}

}
